package com.sfh.ship.adapter;

import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class ShipCursorBaseAdapter<T> extends CursorAdapter
{
    LayoutInflater mInflater;
    
    int mLayout;
    
    public ShipCursorBaseAdapter(Context context, Cursor c,int layout)
    {
        super(context, c, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
        this.mInflater = LayoutInflater.from(context);
        this.mLayout = layout;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public void bindView(View arg0, Context arg1, Cursor arg2)
    {
        
        T hondler = (T)arg0.getTag();
        setViewData(hondler, arg2);
    }
    
    @Override
    public View newView(Context arg0, Cursor arg1, ViewGroup arg2)
    {
        View view = mInflater.inflate(mLayout, arg2, false);
        T v = findHondView(view);
        view.setTag(v);
        return view;
    }
    
    public abstract T findHondView(View view);
    
    public abstract void setViewData(T hondler, Cursor arg2);
    
}
